var ctx
export default class Font {
  constructor(size,path = "Arial",_ctx){
    ctx = ctx || _ctx
    this.ctx = _ctx || ctx
    this.path = path
    this.size = size
    this.h = size
    if (wx.getSystemInfoSync().system.slice(0,3) == "iOS") {
      this.serif = " sans-serif"
    }else{
      this.serif = ""
    }
    if (path.indexOf(".")== -1) {
      this.style = size + "px " + path + this.serif
      //console.log(this.style)
    } else {
      this.style = wx.loadFont(path) //todo
    }
  }
  getWidth(text){
    var font = this.ctx.font
    this.ctx.font = this.style
    var metrics = this.ctx.measureText(text)
    this.ctx.font = font
    return metrics.width
  }
  getHeight(){
    return this.h
  }
}